import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;


public class Day3 {
    public static void main(String[] args) {
        int[] arr = {6,58,10,84,35,8,22,64,1,78,86,71,77};
        PriorityQueue<Double> pq = new PriorityQueue<>((a,b)->b.compareTo(a));
        pq.offer(1.0);
        pq.offer(2.0);
        pq.offer(3.0);
        pq.offer(4.0);
        System.out.println(pq.poll());
  }
    public int halveArray(int[] nums) {
        PriorityQueue<Double> pq = new PriorityQueue<>((a,b)->b.compareTo(a));
        double sum = 0;
        for(int x:nums) {
            pq.offer((double)x);
            sum+=x;
        }
        int count =0 ;
        sum/=2.0;
        while(sum > 0) {
            double tmp = pq.poll()/2.0;
            sum-=tmp;
            pq.offer(tmp);
            count++;
        }
        return count;
    }
    //
    List<List<Integer>> ret = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        int sum = 0;
        dfs(candidates,target,0,sum);
        return ret;
    }
    public void dfs(int[] candidates,int target,int pos,int sum) {
        if(sum >= target) {
            if(sum == target) {
                ret.add(new ArrayList(path));
            }
            return;
        }
        for(int i=pos;i<candidates.length;i++) {
            path.add(candidates[i]);
            sum+=candidates[i];
            dfs(candidates,target,i,sum);
            //回溯
            path.remove(path.size()-1);
            sum-=candidates[i];
        }
    }

}
